package com.janson.generate.controller;


import com.janson.generate.entity.User;
import com.janson.generate.mapper.UserMapper;
import com.janson.generate.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author janson
 * @since 2022-03-15
 */
@RestController
@RequestMapping("/generate/user")
public class UserController {
    @Autowired
    private UserMapper userMapper;
    @GetMapping("/select")
    public User selectUser(long id){
        User users =  userMapper.selectById(id);
        System.out.println(users);
        return users;
    }
    @PostMapping("/insert")
    public int insertUser(User user){
        int insert = userMapper.insert(user);
        return insert;

    }
    @Autowired
    private IUserService iUserService;

    @PostMapping("/update")
    public int updateUser(User user){
        //user.setId(user.getId());
        int i = userMapper.updateById(user);
        System.out.println(i);
        return i;
    }
    @PostMapping("/save")
    public boolean saveUser(User user){
        boolean save = iUserService.save(user);
        return save;
    }
    @GetMapping("/selectList")
    public List<User> selectUserList(){

        List<User> users = userMapper.selectList(null);
        return users;
    }
}

